package manejadores;

/**
 *
 * @author Jose Dario Gimenez
 */
import beans2.TipoRecurso;
import java.sql.*;
import java.util.ArrayList;

public class ManejadorTipoRecurso {

    private TipoRecurso tipoRecurso;
    private ResultSet resultSet;
    private ArrayList list;
    private Connection connection;

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public void setConditionRecurso(String condition, int idRecurso) throws SQLException {
        if (!condition.equalsIgnoreCase("")) {
            condition = " where " + condition;
        }
        list = new ArrayList();
        PreparedStatement statement = connection.prepareStatement("select idtiporecurso, descripcion, movil from tiporecurso" + condition);
        resultSet = statement.executeQuery();
        while (resultSet.next()) {
            tipoRecurso = new TipoRecurso();
            tipoRecurso.setId(resultSet.getInt(1));
            tipoRecurso.setDescripcion(resultSet.getString(2));
            tipoRecurso.setMovil(resultSet.getBoolean(3));
            ManejadorAtributo manejadorAtributo = new ManejadorAtributo();
            manejadorAtributo.setConnection(connection);
            manejadorAtributo.setConditionRecurso("recurso_tiporecurso_atributo.idrecurso=" + idRecurso);
            tipoRecurso.setListAtributos(manejadorAtributo.getList());
            list.add(tipoRecurso);
        }
    }

    public void setConditionTipoRecurso(String condition) throws SQLException {
        if (!condition.equalsIgnoreCase("")) {
            condition = " where " + condition;
        }
        list = new ArrayList();
        PreparedStatement statement = connection.prepareStatement("select idtiporecurso, descripcion, movil from tiporecurso" + condition+" order by idtiporecurso");
        resultSet = statement.executeQuery();
        while (resultSet.next()) {
            tipoRecurso = new TipoRecurso();
            tipoRecurso.setId(resultSet.getInt(1));
            tipoRecurso.setDescripcion(resultSet.getString(2));
            tipoRecurso.setMovil(resultSet.getBoolean(3));
            ManejadorAtributo manejadorAtributo = new ManejadorAtributo();
            manejadorAtributo.setConnection(connection);
            manejadorAtributo.setConditionTipoRecurso("tiporecurso_atributo.idtiporecurso=" + tipoRecurso.getId());
            tipoRecurso.setListAtributos(manejadorAtributo.getList());
            list.add(tipoRecurso);
        }
    }

    public TipoRecurso getTipoRecurso() {
        return tipoRecurso;
    }

    public ArrayList getList() {
        return list;
    }
}